package demoMod.nanaki.patches.events.exordium;

import basemod.ReflectionHacks;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.evacipated.cardcrawl.modthespire.lib.SpireReturn;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.events.AbstractEvent;
import com.megacrit.cardcrawl.events.exordium.ScrapOoze;
import com.megacrit.cardcrawl.localization.EventStrings;
import com.megacrit.cardcrawl.vfx.cardManip.ShowCardAndObtainEffect;
import demoMod.nanaki.NanakiMod;
import demoMod.nanaki.cards.tempCards.GreedyDead;
import demoMod.nanaki.characters.NanakiCharacter;

public class ScrapOozePatch {
    public static final String ID = NanakiMod.makeID("Scrap Ooze");
    private static final EventStrings eventStrings;
    public static final String NAME;
    public static final String[] DESCRIPTIONS;
    public static final String[] OPTIONS;

    @SpirePatch(
            clz = ScrapOoze.class,
            method = SpirePatch.CONSTRUCTOR
    )
    public static class PatchConstructor {
        public static void Postfix(ScrapOoze event) {
            if (AbstractDungeon.player instanceof NanakiCharacter) {
                event.imageEventText.setDialogOption(OPTIONS[5], new GreedyDead());
            }
        }
    }

    @SpirePatch(
            clz = ScrapOoze.class,
            method = "buttonEffect"
    )
    public static class PatchButtonEffect {
        public static SpireReturn<Void> Prefix(ScrapOoze event, int buttonPressed) {
            if (AbstractDungeon.player instanceof NanakiCharacter) {
                int screenNum = ReflectionHacks.getPrivate(event, ScrapOoze.class, "screenNum");
                if (screenNum == 0) {
                    if (buttonPressed == 2) {
                        AbstractDungeon.effectList.add(new ShowCardAndObtainEffect(new GreedyDead(), (float)(Settings.WIDTH / 2), (float)(Settings.HEIGHT / 2)));
                        AbstractEvent.logMetricTakeDamage("Scrap Ooze", "Fled", 0);
                        event.imageEventText.updateBodyText(DESCRIPTIONS[4]);
                        event.imageEventText.clearRemainingOptions();
                        event.imageEventText.updateDialogOption(0, OPTIONS[3]);
                        ReflectionHacks.setPrivate(event, ScrapOoze.class, "screenNum", 1);
                        return SpireReturn.Return(null);
                    } else {
                        event.imageEventText.removeDialogOption(2);
                    }
                }
            }
            return SpireReturn.Continue();
        }
    }

    static {
        eventStrings = CardCrawlGame.languagePack.getEventString(ID);
        NAME = eventStrings.NAME;
        DESCRIPTIONS = eventStrings.DESCRIPTIONS;
        OPTIONS = eventStrings.OPTIONS;
    }
}
